//全局过滤
export const filterWords = (string,length = 12) => {
  let reg=/<\/?.+?\/?>/g;
  let titleStr = string.replace(reg,"");

  let regapc=/[ ]|[&nbsp;]|[&gt;]|[&lt;]/g;
  titleStr=titleStr.replace(regapc,"");

  return titleStr.length <= length ?titleStr:titleStr.substr(0,length) + '...';
}

export const hideMobile = (string) => {
  if(!string) return;
  return string.substr(0,3) + '****'+ string.substr(7,4)
}

//时间戳转换方法    date:时间戳数字
export const formatDayTime = (val) => {
  var timestr = String(val);
 
  if(timestr) {
     if(timestr.length>12){
      timestr=timestr * 1;
     }else{
      timestr=timestr * 1000;
     }
      let date = new Date(timestr);  //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      
      let Y = date.getFullYear();
      let M = ("0" + (date.getMonth() + 1)).slice(-2);
      let D = ("0" + date.getDate()).slice(-2);

      return Y + '-' + M + '-' + D ;
    
  } else {
      return '';
  }
  
}

export const  formatDate = (dateStr) => {
  var dateArr = dateStr.replace(",","").split(" ");
    var month = "";
    if(dateArr[0] == "Jan" || dateArr[0] == "一月"){
      month = 1;
    }else if(dateArr[0] == "Feb" || dateArr[0] == "二月"){
      month = 2;
    }else if(dateArr[0] == "Mar" || dateArr[0] == "三月"){
      month = 3;
    }else if(dateArr[0] == "Apr" || dateArr[0] == "四月"){
      month = 4;
    }else if(dateArr[0] == "May"|| dateArr[0] == "五月"){
      month = 5;
    }else if(dateArr[0] == "Jun"|| dateArr[0] == "六月"){
      month = 6;
    }else if(dateArr[0] == "Jul"|| dateArr[0] == "七月"){
      month = 7;
    }else if(dateArr[0] == "Aug"|| dateArr[0] == "八月"){
      month = 8;
    }else if(dateArr[0] == "Sep"|| dateArr[0] == "九月"){
      month = 9;
    }else if(dateArr[0] == "Oct"|| dateArr[0] == "十月"){
      month = 10;
    }else if(dateArr[0] == "Nov"|| dateArr[0] == "十一月"){
      month = 11;
    }else if(dateArr[0] == "Dec" || dateArr[0] == "十二月"){
      month = 12;
    }
    
    return dateArr[2] +"-"+month+"-"+dateArr[1];
}


